package com.likersai.opon.pojo.bo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * 分页模型
 *
 * @author sun.ye
 *
 * @since 2021-05-06 20:25
 */
@Data
@ApiModel(value = "分页查询模型",description = "分页查询的数据模型，前端Grid组件可与之适配")
public class PageBO<T> {

    @ApiModelProperty(value = "当前页码")
    private int pageNum;
    @ApiModelProperty(value = "总页码")
    private int pageCount;
    @ApiModelProperty(value = "页长")
    private int pageSize;
    @ApiModelProperty(value = "总记录数")
    private long totalCount;
    @ApiModelProperty(value = "当前页数据")
    private List<T> rows;
    
    public PageBO () {}
    
    public static <T> PageBO<T> getPage(List<T> rows,int totalCount) {
        PageBO<T> page = new PageBO<>();
        page.setRows(rows);
        page.setTotalCount(totalCount);
        return page;
    }
    
    public int getPageCount(){
        if (pageSize == 0){
            pageCount = (int) totalCount;
        }else {
            pageCount = (int) Math.ceil((float)totalCount / pageSize);
        }
        return pageCount;
    }

}